// pages/education/index.js
import DB from '../../utils/db';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    confirmBtn: { content: '确定', variant: 'base' },
    dialogKey: '',
    showConfirm: false,
    showWarnConfirm: false,
    showLightConfirm: false,
  },

  showDialog(e) {
    const { key } = e.currentTarget.dataset;
    this.setData({ [key]: true, dialogKey: key });
  },

  closeDialog() {
    const { dialogKey } = this.data;
    this.setData({ [dialogKey]: false });
    console.log("确认删除")
  },

  onCertificateInput(e){
    this.setData({
      'form.certificate': e.detail.value
    })
  },

  updateQualificationCertificate(){
    wx.showLoading({
      title: '',
    });
    DB.update('updateQualificationCertificate', this.data.form).then(() => {
      wx.hideLoading();
      wx.reLaunch({
        url: `/pages/createResume/index`,
      });
    }).catch(() => {
      wx.hideLoading();
      wx.showToast({
        title: '更新失败',
        icon: 'error',
        duration: 2000
      });
    });
  },

  addQualificationCertificate(){
    // console.log(this.data.openId)
    this.data.form.openId = this.data.openId
    // console.log(this.data.form)
    wx.showLoading({
      title: '',
    });
    DB.add('addQualificationCertificate', this.data.form).then(() => {
      wx.hideLoading();
      wx.reLaunch({
        url: `/pages/createResume/index`,
      });
    }).catch(() => {
      wx.hideLoading();
      wx.showToast({
        title: '添加失败',
        icon: 'error',
        duration: 2000
      });
    });
  },

  selectQualificationCertificate(id) {
    DB.select('selectQualificationCertificate', id).then((resp) => {
          
      this.setData({
        form: resp.result.data,
        count: 1
      });
      wx.hideLoading();
    }).catch(() => {
      console.log(e);
      this.setData({
        showUploadTip: true
      });
      wx.hideLoading();
    });
  
  },

  deleteQualificationCertificate(){
    wx.showLoading({
      title: '',
    });
    DB.delete('deleteQualificationCertificate', this.data.form).then(() => {
      wx.hideLoading();
      wx.reLaunch({
        url: `/pages/createResume/index`,
      });
    }).catch(() => {
      wx.hideLoading();
      wx.showToast({
        title: '删除失败',
        icon: 'error',
        duration: 2000
      });
    });

  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      openId: wx.getStorageSync("openId")
    })
    if(options.id != 'undefined'){
      wx.showLoading({
        title: '数据加载中...', // 这里设置提示词
        mask: true // 显示透明蒙层
      });
      this.selectQualificationCertificate(options.id)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage() {

  // }
})